<!--
 * @Description: 
 * @Version: 1.0
 * @Author: Will
 * @Date: 2023-03-07 17:21:40
 * @LastEditors: Will
 * @LastEditTime: 2023-03-08 18:03:28
 * @FilePath: \cloud-space\components\tree\tree-item.vue
 * Copyright (C) 2023 Will. All rights reserved.
-->
<template>
  <view class="tree-item">
    <block v-if="mutiple">
      <view class="lists">
        <block v-for="(item) in dataList" :key="item.id">
          <label class="label">
            <view class="value" @click.stop="changeShow(item)">
              <image :style="{ opacity: item[dataChildren].length > 0 ? 1 : 0 }" :src="img[item.isShow ? 1 : 0]"
                mode="aspactFill">
              </image>
              {{ item[dataLabel] }}
            </view>
            <view>
              <checkbox :value="String(item[dataValue])" :checked="item.checked" />
            </view>
          </label>
          <l-tree-item v-show="item.isShow" :dataList.sync="item[dataChildren]" :mutiple="mutiple"></l-tree-item>
        </block>
      </view>
    </block>
    <block v-else>
      <view class="lists">
        <block v-for="(item) in dataList" :key="item.id">
          <label class="label">
            <view class="value" @click.stop="changeShow(item)">
              <image :style="{ opacity: item[dataChildren].length > 0 ? 1 : 0 }" :src="img[item.isShow ? 1 : 0]"
                mode="aspactFill">
              </image>
              {{ item[dataLabel] }}
            </view>
            <view>
              <radio :value="String(item[dataValue])" :checked="item.checked" />
            </view>
          </label>
          <l-tree-item v-if="item.isShow" :dataList.sync="item[dataChildren]" :mutiple="mutiple"></l-tree-item>
        </block>
      </view>
    </block>
  </view>
</template>

<script>

import lTreeItem from "@/components/tree/tree-item"
export default {
  components: {
    lTreeItem
  },
  name: 'l-tree-item',
  props: {
    dataList: {
      type: Array,
      default: () => []
    },
    mutiple: {
      type: Boolean,
      default: false
    },
    dataChildren:{
      type:String,
      default:'child'
    },
    dataValue:{
      type:String,
      default:'id'
    },
    dataLabel:{
      type:String,
      default:'title'
    }
  },
  data() {
    return {
      img: ['../../static/img/icon/arrow-s.png', '../../static/img/icon/arrow-down-2.png']
    }
  },
  watch: {

  },
  created() {},
  methods: {
    changeShow(item) {
      item.isShow = !item.isShow
      this.$forceUpdate();
    },

  },
}
</script>

<style lang="less" scoped>
.lists {
  background: #fff;
  padding: 0 0 0 30upx;
}

.checkbox,
.radio {
  .label {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 10upx 0;
    .border-1px(bottom);

    .value {
      display: flex;
      flex-direction: row;
      align-items: center;
      font-size: 30upx;

      image {
        width: 24upx;
        height: 24upx;
        margin-right: 10upx;
      }
    }
  }
}
/deep/ .uni-checkbox-wrapper {
  margin-top: -8upx;
}
</style>
